#pragma once

#include "condition.h"
#include "action.h"


namespace BAA
{

	class Action_Socialize_Talk:public Action
	{
	public:


		Action_Socialize_Talk():Action("talk")
		{
			
		}


		virtual void Initialize(Role * roleParent, AgentPointerMap * targets)
		{
			Action::Initialize(roleParent, targets);
			mRange.y = -5.0f;
			mRange.y = 5.0f;

			mAngerFactor = 0.2f;
			mLikeFactor = 0.6f;
			mSocialContact = 0.8f;


			mPostcondition->push_back("socialize");

			mPreconditions = new Conditions();

			AddConsequence("socialize", 0.3f);
			AddConsequence("loudness", 0.3f);

		}

		virtual void PrepareConditions()
		{
			// nothing to do to run.
		}

		virtual void ApplyActionToInternalSate()
		{
			// reduce need for social contact
			RoleParent()->Self()->Properties()->mSocialContact->ModifyValue(-0.1f);
		};

		virtual float CalculateStateUtility()
		{
			AgentProperties * properties = mRoleParent->Self()->Properties();

			// this could be a condition rather then calculated during the utility
			Emotion * anger = (*mRoleParent->Emotions())["anger"];
			Emotion * like =  (*mRoleParent->Emotions())["like"];

			if(anger == NULL || like == NULL)
				return 0.0f;


			// average out anger
			float angerVal = (properties->mAnger->GetValue() + anger->GetValue())/ 2.0f;


			// Talk to your friend when your not angry with them
			float emotionUtility = (1-abs(mLikeFactor - like->GetValue())) - (1- abs(mAngerFactor - angerVal));
				

			float personalityUtility = (1- abs( mSocialContact - properties->mSocialContact->Value()));

			return MathHelper::clamp(&mRange,emotionUtility + (0.5f)*personalityUtility);
		}






		~Action_Socialize_Talk()
		{

		}

	protected:
		// any members

		Vector2 mRange;

		float mAngerFactor;
		float mLikeFactor;
		float mSocialContact;
	};// end class
}// end namespace
